# -*- coding: utf-8 -*-
# @Time: 2023/4/14 23:14
# @File: decorators.py
# @Desc:装饰器

from flask import g, redirect, url_for
from functools import wraps


# 登录装饰器
def loginrequired(func):
    @wraps(func)
    def inner(*args, **kwargs):
        if hasattr(g, "user"):  # 如果g有"user"对象
            return func(*args, **kwargs)
        else:
            return redirect(url_for("front.login"))

    return inner

